package com.lmx.wuzhangshao.base;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * @author Leung
 * @date 2020/8/16 10:47
 */
public abstract class BaseFragment extends Fragment {

    /**
     * 上下文
     */
    public Activity mActivity;
    /**
     * 根视图
     */
    private View mRootView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = initViews(inflater, container, savedInstanceState);
        return mRootView;
    }

    /**
     * 初始化视图
     *
     * @param inflater 填充布局
     * @param container 容器
     * @param savedInstanceState 数据
     * @return 视图
     */
    public abstract View initViews(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    /**
     * 初始化数据
     */
    public void initData() {

    }
}
